package othello.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.ParallelGroup;
import javax.swing.GroupLayout.SequentialGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class GeneralSettingsPanel extends JPanel {
	private static final long serialVersionUID = 1L;

	public GeneralSettingsPanel() {
        final JLabel[] labels = {new JLabel("Draw games:")};
        final JComponent[] components = {new JCheckBox()};

        final GroupLayout layout = new GroupLayout(this);
        setLayout(layout);
        ParallelGroup pc1 = layout.createParallelGroup(GroupLayout.Alignment.LEADING);
        ParallelGroup pc2 = layout.createParallelGroup(GroupLayout.Alignment.LEADING);
        SequentialGroup sg1 = layout.createSequentialGroup();
        for (int i = 0; i < labels.length; i++) {
            pc1.addComponent(labels[i]);
            pc2.addComponent(components[i]);
            sg1.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(labels[i]).addComponent(components[i]));
        }

        final JButton b = new JButton("Save");
        b.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                getRootPane().getJMenuBar().getMenu(0).getItem(0).setEnabled(true);
                b.setEnabled(false);
                Othello.setDrawBoard(((JCheckBox)components[0]).isSelected());
                validate();
            }
        });
        pc2.addComponent(b);
        sg1.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(b));

        layout.setAutoCreateGaps(true);
        layout.setAutoCreateContainerGaps(true);
        layout.setHorizontalGroup(layout.createSequentialGroup().addGroup(pc1).addGroup(pc2));
        layout.setVerticalGroup(sg1);
    }
}
